import coe.pumbaa.Role
import coe.pumbaa.User
import coe.pumbaa.SecUserSecRole
class BootStrap {

    def init = { servletContext ->
        
        println "Start."
        println "Initial Role"
        //Role
        def adminRole = new Role(
            type: 'admin',
            level: 0
        ).save(flush:true)
        
        def staffRole = new Role(
            type: 'teacher',
            level: 1
        ).save(flush:true)
        
        def anonymousRole = new Role(
            type: 'anonymous',
            level: 4,
        ).save(flush:true)
        
        println "Initial User."
        //User
        def admin = new User(
            email: 'sysadmin',
            password: 'sysadmin',
            fname: 'ผู้ดูแลระบบ',
            lname: 'admin',
            displayName: 'Admin',
            phoneNO: '0801112222',
            status: User.ACTIVE_USER,
            role: adminRole,
            
            enabled: true,
            accountExpired: false,
            accountLocked: false,
            passwordExpiored: false
        ).save(failOnError:true)
        
        def teacher = new User(
            email: 'teacher',
            password: 'teacher',
            fname: 'อาจารย์',
            lname: 'บุคลากร',
            displayName: 'Teacher',
            phoneNO: '0801112222',
            status: User.ACTIVE_USER,
            role: staffRole,
            
            enabled: true,
            accountExpired: false,
            accountLocked: false,
            passwordExpiored: false
        ).save(failOnError:true)
        
        def anonymous = new User(
            email: 'anonymous',
            password: 'anonymous',
            fname: 'anonymous',
            lname: 'anonymous',
            displayName: 'Anonymous',
            phoneNO: 'anonymous',
            status: User.ACTIVE_USER,
            role: anonymousRole,
            
            enabled: true,
            accountExpired: false,
            accountLocked: false,
            passwordExpiored: false
        ).save(failOnError:true)
    
    }
    def destroy = {
    }
}
